Learning Objectives

After completing this lesson, you’ll be able to:

Instructions

In this lesson, you will:

Resources

AttributeFilter

The AttributeFilter transformer directs records by values in a chosen attribute. It is not a binary test (Yes/No) but a way to separate many values for a single attribute, for example:

AttributeFilter example

To separate this data, you would have to use seven Tester transformers, so using a single AttributeFilter saves space on the workspace canvas.

Note

Use the Import... button to add attributes from existing datasets quickly.

Note

In almost every scenario using multiple Tester transformers, it's possible to use a different filtering transformer to achieve the same result but using much less space on the canvas.

The AttributeFilter also works with numeric values; however, its only "operator" is to find equivalency (=), so you will rarely use it for arithmetical tests. In that scenario, the better solution is the AttributeRangeFilter.

AttributeRangeFilter

The AttributeRangeFilter carries out the same operation as the AttributeFilter, except it can handle a range of numeric values instead of just a simple one-to-one match.

For example, we might want to separate data based on a range of snowfall values, like so:

AttributeRangerFilter example

Notice that the AttributeRangeFilter parameters dialog has a Generate... button, which generates ranges automatically from a set of user-defined extents.

Which Transformer Should I Use?

If the Tester, TestFilter, and AttributeFilter all filter records based on an attribute condition, then what’s the difference? When would I use each?

You can also refer to this table:
  Single Test Multiple Tests Test Type Operators Attributes
  Single
Clause
Multi
Clause
Single
Clause
Multi
Clause
String Numeric    
Tester Y Y Y Y 16 Multiple
TestFilter Y Y Y Y Y Y 16 Multiple
AttributeFilter Y Y Y 1 1
AttributeRangeFilter Y Y Y 6 1

Exercise

Sven continues to work on his workspace. He has a few more filtering tasks to do:

  1. Filter parks by popularity to create a Popularity attribute
  2. Filter by Neighborhood and only write out parks in the Downtown neighborhood

1) Open Starting Workspace

2) Add AttributeRangerFilter

Added AttributeRangeFilter

Choosing a source attribute

Setting ranges

3) Add AttributeCreators and Run Workspace

Now we have filtered records into Popular, Not Popular, and Unfiltered parks, we'd like to set the value of a new Popularity attribute based on this filter.

Setting Popularity

Filtering by popularity

4) Add AttributeFilter

Next, we need to divide the data by Neighborhood. For now, we'd like to only write data in the Downtown neighborhood. However, we suspects we might need to work with data from other neighborhoods later on, so we doesn't want to simply use a Tester to grab only the Downtown parks. Instead, we'll use an AttributeFilter to split the data into many streams based on the value of the Neighborhood attribute.

Added AttributeFilter

Import > From Data Cache

Selecting data caches

Choosing attribute to import from

Selecting values

Ports added

 

Connected to writer feature type

5) Run Workspace and Inspect Output

Written parks data

Leave Us Feedback on This Lesson